/**
 * @brief I2C driver header
 * @author Gilad Avidov
 */
#ifndef I2C_H_INCLUDED
#define I2C_H_INCLUDED

#define SCL         P1_0
#define SDA         P1_1

typedef enum {
    I2C_WR = 0,
    I2C_RD = 1,
} i2c_op_t;

void i2c_init();

void i2c_stop();

void i2c_reset();

/* @return zero on success (ACK) nonzero on failure (NACK) */
unsigned char i2c_send_byte(unsigned char byte);

/*
 * @return zero on success (ACK) nonzero on failure (NACK)
 * @is_last true on last receive byte
 */
void i2c_recv_byte(xdata unsigned char *byte, bit is_last);

/* @return zero on success (ACK) nonzero on failure (NACK)
 * @op i2C_ RD/WR
 */
unsigned char i2c_send_address(unsigned char seven_bit_addr, i2c_op_t op);

#endif // I2C_H_INCLUDED
